package io.renren.modules.canteens.dao;

import io.renren.common.dao.BaseDao;
import io.renren.modules.canteens.dto.AuxiliaryMaterialsmxDTO;
import io.renren.modules.canteens.entity.AuxiliaryMaterialsmxEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 辅材采购明细表
 *
 * @author 罗胜平 781757616@qq.com
 * @since 1.0.0 2019-11-22
 */
@Mapper
public interface AuxiliaryMaterialsmxDao extends BaseDao<AuxiliaryMaterialsmxEntity> {
    @Select("SELECT A.* from  canteens_auxiliary_materi A where A.auxiliary_materials_id = '${smallCanteenPurchaseId}' GROUP BY A.supplier_id  ")
    List<AuxiliaryMaterialsmxDTO> getsupplierOrder(long smallCanteenPurchaseId);
    @Select("SELECT (select B.supplier_name from canteens_supplier B where A.supplier_id = B.supplier_id ) as supplier_name, " +
            " (select B.unit from canteens_food B where A.food_id = B.food_id ) as unit, " +
            " (select B.food_name from canteens_food B where A.food_id = B.food_id ) as food_name, " +
            " C.meal_time,A.* from  canteens_auxiliary_materialsmx A ,canteens_auxiliary_materi C" +
            " where A.auxiliary_materials_id = c.auxiliary_materials_id and  A.auxiliary_materials_id = '${smallCanteenPurchaseId}' and  A.supplier_id = '${supplierId}' ")
    List<AuxiliaryMaterialsmxDTO> getOrderMx(long smallCanteenPurchaseId, long supplierId );
    @Select("SELECT sum(unit_price*arrival_num) as totalPrice from  canteens_auxiliary_materialsmx where auxiliary_materials_id = '${smallCanteenPurchaseId}' and  supplier_id = '${supplierId}' ")
    AuxiliaryMaterialsmxDTO getTotalPrice(long smallCanteenPurchaseId,long supplierId );
    @Select("SELECT sum(unit_price*arrival_num) as totalPrice from  canteens_auxiliary_materialsmx where auxiliary_materials_id = '${smallCanteenPurchaseId}'  ")
    AuxiliaryMaterialsmxDTO getTotalMony(long smallCanteenPurchaseId);
}